<?php
namespace app\common\model\newmodel;

use think\Model;

class UserAgency extends Model
{
    protected $table = 'user_agency';
    protected $pk = 'id';

    /**
     * 通过 user_id 获取 agency_id
     */
    public static function getAgencyIdByUserId($user_id)
    {
        return self::where('user_id', $user_id)->value('agency_id');
    }

    /**
     * 通过 agency_id 获取所有 user_id
     */
    public static function getUserIdsByAgencyId($agency_id)
    {
        return self::where('agency_id', $agency_id)->column('user_id');
    }

    /**
     * 添加 user-agency 关联
     */
    public static function addUserAgency($user_id, $agency_id)
    {
        return self::create([
            'user_id' => $user_id,
            'agency_id' => $agency_id,
        ]);
    }

    /**
     * 删除 user-agency 关联
     */
    public static function delUserAgency($user_id)
    {
        return self::where('user_id', $user_id)->delete();
    }
}

